package pkg

import (
	"context"
	"github.com/qiniu/go-sdk/v7/storagev2/credentials"
	"github.com/qiniu/go-sdk/v7/storagev2/http_client"
	"github.com/qiniu/go-sdk/v7/storagev2/uploader"
	"mime/multipart"
)

// 七牛云上传文件
func QiNiuYun(reader multipart.File) error {

	accessKey := "c2RytiFZrxjm8CF4ZpPrbhBdEUR_MIb8gJKvRKpN"
	secretKey := "rus_ItGAPWc9VQrZizz7abgBvGzhBUyQczYR4Yzv"

	mac := credentials.NewCredentials(accessKey, secretKey)
	bucket := "laomachi"
	key := "github-x.png"
	uploadManager := uploader.NewUploadManager(&uploader.UploadManagerOptions{
		Options: http_client.Options{
			Credentials: mac,
		},
	})
	err := uploadManager.UploadReader(context.Background(), reader, &uploader.ObjectOptions{
		BucketName: bucket,
		ObjectName: &key,
		CustomVars: map[string]string{
			"name": "github logo",
		},
	}, nil)
	if err != nil {
		return err
	}
	return nil
}
